/*
 * @(#) RegistAdmin.java 2018年2月7日 下午12:18:18
 *
 * Copyright 2018 CIMIP, Inc. All rights reserved.
 * H-VISIONS PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */package cn.hc.share.service.impl;

import java.util.UUID;

import javax.annotation.PostConstruct;

import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import cn.hc.share.dao.MenuDao;
import cn.hc.share.dao.UserDao;
import cn.hc.share.entity.Menu;
import cn.hc.share.entity.User;

@Component
public class RegistAdmin
{
	
	@Value("#{jdbc.salt}")
	private String salt;
	
	@Autowired
	private UserDao userDao;
	
	@PostConstruct
	public void init()
	{
		String name="admin";
		String password="admin";
		String pwd = DigestUtils.md5Hex(
				salt+password.trim());
		User user = userDao.findUserByName(name);
		if(user==null) {
			String id = UUID.randomUUID().toString();
			user=new User(id,name,pwd,"",name,"");
			int num = userDao.addUser(user);
			if(num!=1){
				throw new RuntimeException("添加失败!");
			}
			System.out.println("添加admin成功");
		}else {
			System.out.println("已存在admin");
		}
	}
	
}





